package des;

import com.youkeda.model.User;

import java.sql.ResultSet;
import java.util.Scanner;

/**
 * @author 刘正星
 * @version 1.0.0
 * @ClassName DesTest.java
 * @Description TODO
 * @createTime 2020年11月08日 22:42:00
 */
public class DesTest {


    public static void main(String[] args) throws Exception {
        System.out.println("请输入用户名密码！");
        Scanner scanner = new Scanner(System.in);
        String userName= scanner.next();
        String pwd = scanner.next();

        String secretKey = "aaaabbbb";
        String dpwd = DesUtil.encrypted(pwd,secretKey);
        String deStr = DesUtil.decrypted(dpwd,secretKey);
        String duserName = DesUtil.encrypted(userName,secretKey);
        String euserName = DesUtil.decrypted(duserName,secretKey);
        MySqlConnBean mySqlConnBean = new MySqlConnBean();
        mySqlConnBean.OpenConn("root","Lzx0203.","test","121.89.173.87");
        String sql="select * from user";
        ResultSet resultSet = mySqlConnBean.executeQuery(sql);
//        while (resultSet.next()){
//            System.out.println("userName: "+resultSet.getString("username"));
//        }
        String insert = "INSERT INTO `user` ( `password`, `username`) VALUES('"+dpwd+"', '"+duserName+"')";

        boolean result = mySqlConnBean.execute(insert);
        mySqlConnBean.closeStmt();
        mySqlConnBean.closeConn();
        System.out.println("加密后的密文：密码："+dpwd+" 用户名："+duserName);
        System.out.println("解密后的明文：密码："+deStr+" 用户名："+euserName);
        System.out.println("密钥："+secretKey);
    }
}